home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / RANDBWR.C < prev    next >
Encoding:
Text File  |  1991-08-05  |  1.6 KB  |  51 lines

  1. /* RANDBWR.C --- p. 655 */
  2. #include <stdio.h>
  3. #include <dos.h>
  4. #define FCB_CREAT 0x16
  5. #define FCB_CLOSE 0x10
  6. char buffer[256] = "Testing randbwr...";
  7. main()
  8. {
  9.     char input[80], far *old_dta;
  10.     int option;                /* Option for parsfnm */
  11.     struct fcb fcb;            /* File Control Block, FCB  */
  12.     int i, result;
  13.     printf("Enter name of NEW file to which we will "
  14.            "write two 128-byle records:\n(only drive and file "
  15.            "name allowed, for example, A:MYFILE.DAT):");
  16.     gets(input);
  17.             /* parse file name using 'parsfnm' and an FCB */
  18.     option = 1;            /* means skip leading separators  */
  19.     parsfnm(input, &fcb, option);
  20.     printf("Writing to\nDrive number: %d\n File name: %s\n",
  21.                 fcb.fcb_drive, fcb.fcb_name);
  22.             /* Now create the file using DOS function 16h (this
  23.              * is not the same as "_creat" which uses handles */
  24.     if(bdosptr(FCB_CREAT, &fcb, 0) == -1)
  25.     {
  26.         printf("File creating file!\n");
  27.         exit(1);
  28.     }
  29.             /* Save current disk transfer address and set up
  30.              * the new one as the DTA */
  31.     old_dta = getdta();
  32.     setdta(buffer);
  33.             /* Now set up the record size and start block */
  34.     fcb.fcb_recsize = 128;
  35.     fcb.fcb_random = 0L;            /* start at record 0 */
  36.     result = randbwr(&fcb, 2);
  37.     printf("result = %d\n", result);
  38.     if(result == 0)
  39.         printf("Write ok\n");
  40.     if(result == 1)
  41.         printf("Disk full!\n");
  42.         /* Finlly, close the file using DOS function 10h (this
  43.          * is not the as "_close" which uses handles) */
  44.     if(bdosptr(FCB_CLOSE, &fcb, 0) == -1)
  45.     {
  46.         printf("Error colsing file!\n");
  47.         exit(1);
  48.     }
  49.                     /* Reset DTA to old value  */
  50.     setdta(old_dta);
  51. }